﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Soussous.Business;
using Soussous.DAO.Impl;

using log4net;
using log4net.Config;


namespace Soussous.Template
{
    public partial class connexion : System.Web.UI.Page
    {

        private static readonly ILog log = LogManager.GetLogger(typeof(connexion));


        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Submit_form(object sender, EventArgs e)
        {
            
            string msg = "";
            if (email.Text == "")
            {
                msg += "<li>Please fill the email address</li>";
                log.Error("Please fill the email address.");
            }
            if (password.Text == "")
            {
                msg += "<li>Please fill the password</li>";
                log.Error("Please fill the password");     
            }

            if ("" == msg)
            {
                User theUser = UserDAO.getInstance().authenticate(email.Text, password.Text);
                if (theUser == null)
                {
                    msg += "<li>This user is not living...yet</li>";
                    log.Error("This user is not living...yet.");
                }
                else 
                {
                    HttpContext.Current.Session["user"] = theUser;
                    log.Info("Connected.");
                    Response.Redirect("home.aspx");
                }
            }   
        }
    }
}